define('component/main/NavTag', ['component/wxUtils', 'text!./NavTag.html'], function ({ showTitle}, template) {
  return {
    template: template,
    name: 'NavTag',
    props: {
      value: Object,
      list: {
        type: Array,
        default() {
          return []
        }
      }
    },
    data() {
      return {
        tagBodyLeft: 5
      }
    },
    methods: {
      handlescroll(e) {
        var type = e.type
        let delta = 0
        if (type === 'DOMMouseScroll' || type === 'mousewheel') {
          delta = (e.wheelDelta) ? e.wheelDelta : -(e.detail || 0) * 40
        }
        this.handleScroll(delta)
      },
      handleScroll(offset) {
        if (offset > 0) {
          this.tagBodyLeft = Math.min(0, this.tagBodyLeft + offset)
        } else {
          if (this.$refs.scrollOuter.offsetWidth < this.$refs.scrollBody.offsetWidth) {
            if (this.tagBodyLeft < -(this.$refs.scrollBody.offsetWidth - this.$refs.scrollOuter.offsetWidth)) {
              this.tagBodyLeft = this.tagBodyLeft
            } else {
              this.tagBodyLeft = Math.max(this.tagBodyLeft + offset, this.$refs.scrollOuter.offsetWidth - this.$refs.scrollBody.offsetWidth)
            }
          } else {
            this.tagBodyLeft = 0
          }
        }
      },
      handleTagsOption(type) {
        if (type === 'close-all') {
          // 关闭所有，除了home
          let res = this.list.filter(item => item.meta.homepage)
          this.$emit('on-close', res, 'all')
        } else {
          // 关闭除当前页和home页的其他页
          let res = this.list.filter(item => item.name === this.value.name || item.name === 'home')
          this.$emit('on-close', res, 'others')
        }
      },
      handleClose(e, name) {
        let res = this.list.filter(item => item.name !== name)
        this.$emit('on-close', res, undefined, name)
      },
      handleClick(item) {
        this.$emit('input', item)
      },
      showTitleInside(item) {
        return showTitle(item, this)
      }
    }
  }
})
